package com.maybach.web.framework.util;

import com.maybach.core.ao.FlowApplyAO;
import com.maybach.util.SpringContextUtil;
import com.maybach.workflow.common.api.IFlowEngine;
import com.maybach.workflow.common.ext.FlowTaskInfo;
import com.maybach.workflow.common.model.FlowApplyDO;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by houenxun on 16/1/25.
 */
public class FlowTool {
    @Autowired
    protected FlowApplyAO flowApplyAO;
    @Autowired
    protected IFlowEngine flowEngine;


    public List<FlowTaskInfo> getTasks(Long flowId, boolean filter) {
        return this.getFlowEngine().getTasks(flowId, filter);
    }

    public List<FlowTaskInfo> getTasksByApply(FlowApplyDO flowApplyDO, boolean filter) {
        return this.getFlowApplyAO().getTasksByApplyId(flowApplyDO, filter);
    }

    public FlowApplyAO getFlowApplyAO() {
        if (null == flowApplyAO) {
            synchronized (this) {
                if (null == flowApplyAO) {
                    flowApplyAO = SpringContextUtil.getBean(FlowApplyAO.class);
                }
            }
        }
        return flowApplyAO;
    }

    public IFlowEngine getFlowEngine() {
        if (null == flowEngine) {
            synchronized (this) {
                if (null == flowEngine) {
                    flowEngine = SpringContextUtil.getBean(IFlowEngine.class);
                }
            }
        }
        return flowEngine;
    }
}
